package com.the.ui.page.fragment

import android.view.View
import androidx.recyclerview.widget.ItemTouchHelper
import com.the.ui.R
import com.the.ui.data.bean.SlideCardBean
import com.the.ui.data.repository.DataRepository
import com.the.ui.databinding.FragmentSlideCardBinding
import com.the.ui.page.adapter.SlideCardAdapter
import com.the.ui.viewmodel.request.SlideCardViewModel
import com.the.ui.widge.slidecard.SlideCardCallback
import com.the.ui.widge.slidecard.SlideCardLayoutManager
import com.theone.mvvm.core.base.fragment.BaseCoreFragment
import com.theone.mvvm.ext.qmui.setTitleWitchBackBtn

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 * @author The one
 * @date 2021-11-24 15:50
 * @describe 自定义LayoutManger - 仿探探效果
 * @email 625805189@qq.com
 * @remark
 */
class SlideCardFragment :
    BaseCoreFragment<SlideCardViewModel, FragmentSlideCardBinding>() {

    private val mAdapter: SlideCardAdapter by lazy {
        SlideCardAdapter()
    }

    override fun initView(root: View) {
        setTitleWitchBackBtn(R.string.slide_card)
        mBinding.recyclerView.run {
            // 自定义LayoutManger
            layoutManager =
                SlideCardLayoutManager(context)
            adapter = mAdapter
        }
        DataRepository.INSTANCE.getSlideCardListData().let {
            val callback =
                SlideCardCallback<SlideCardBean>(
                    mAdapter
                )
            val helper = ItemTouchHelper(callback)
            helper.attachToRecyclerView(mBinding.recyclerView)
        }

    }

    override fun onLazyInit() {
        mViewModel.requestNewData()
    }

    override fun createObserver() {
        mViewModel.getResponseLiveData().observeInFragment(this) {
            mAdapter.setList(it)
        }
    }

}